package com.hankol.community.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.baselibrary.bean.VideoReadBean;
import com.hankol.community.fragment.VideoPageFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * 首页-- 视频 页
 */
public class VideoPageAdapter extends FragmentStateAdapter {
    private List<VideoReadBean.DataBeanX.DataBean> beanList;
    private ArrayList<VideoPageFragment> fragments = new ArrayList<>();

    public ArrayList<VideoPageFragment> getFragments() {
        return fragments;
    }

    public VideoPageAdapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);
        beanList = new ArrayList<>();
    }

    public void setDataList(List<VideoReadBean.DataBeanX.DataBean> beanList) {
        this.beanList = beanList;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        VideoPageFragment videoDetailsFragment = VideoPageFragment.Companion.newInstance(beanList.get(position).getId());
        fragments.add(videoDetailsFragment);
        return videoDetailsFragment;
    }

    @Override
    public int getItemCount() {
        return beanList.size();
    }
}